import request from "@/utils/request";

const BASE_URL = "/api/v1/regions";

// 类型定义
interface FormData {
  areaCode?: string;
}

interface Item {
  id: string;
  treePath: string;
  pid: string;
  shortname: string;
  name: string;
  mergerName: string;
  level: number | null;
  pinyin: string;
  code: number | null;
  zipCode: string;
  first: string;
  lng: string;
  lat: string;
  areaCode: string;
  parentAreaCode: number | null;
}

const RegionAPI = {
  /**
   * 获取家族分页列表
   * @param {Object} queryParams 查询参数
   * @returns {Promise} 用户分页列表
   */
  getPage(queryParams: FormData): Promise<Item[]> {
    console.log(queryParams);
    return request({
      url: `${BASE_URL}/getRegion`,
      method: "GET",
      data: { areaCode: queryParams.areaCode },
    });
  },

  /**
   * 获取区域选项数据
   * @param {Object} params 查询参数
   * @returns {Promise} 区域选项列表
   */
  getOptions(params: { type: number; areaCode: string | number }): Promise<Item[]> {
    return request({
      url: `${BASE_URL}/getRegion`,
      method: "GET",
      data: params,
    });
  },
};

export default RegionAPI;
